//
//  MyShopSearchTabVC.m
//  BusinessMarket
//
//  Created by Michael Li on 2019/2/24.
//  Copyright © 2019年 Michael Li. All rights reserved.
//

#import "MyShopSearchTabVC.h"
#import "HomeModel.h"
#import "MyShopDemandCell.h"
#import "MyShopServiceCell.h"
#import "ServiceModel.h"
#import "WriteRequirementTitleCell.h"

@interface MyShopSearchTabVC ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate,MyShopDemandCellDelegate,MyShopServiceCellDelegate>
@property(nonatomic,strong) NSMutableArray *demandOnLineArray;
@property(nonatomic,strong) NSMutableArray *demandOffLineArray;
@property(nonatomic,strong) NSMutableArray *serviceOnLineArray;
@property(nonatomic,strong) NSMutableArray *serviceOffLineArray;
@property(nonatomic,strong) NSMutableArray *dataOnLineMuta;
@property(nonatomic,strong) NSMutableArray *dataOffLineMuta;
@property(nonatomic,strong) NSString *urlString;
@property(nonatomic,strong) NSDictionary *dict;
@property(nonatomic,assign) NSInteger pageNum;
@property(nonatomic,assign) NSInteger pageSize;
@property(nonatomic,strong) HomeModel *downMode;
@property(nonatomic,strong) HomeModel *upModel;
@property(nonatomic,strong) AFHTTPSessionManager *manager;
@property(nonatomic,strong) NSIndexPath *indexPath;
@property(nonatomic,assign) NSInteger tag;
@end
static NSString *identifierTitle = @"titleCell";
static NSString *identifierNeed = @"MyShopDemandCell";
static NSString *identifierService = @"MyShopServiceCell";
@implementation MyShopSearchTabVC
-(NSMutableArray *)demandOnLineArray
{
    if (!_demandOnLineArray) {
        _demandOnLineArray = [NSMutableArray array];
    }
    return _demandOnLineArray;
}
-(NSMutableArray *)demandOffLineArray
{
    if (!_demandOffLineArray) {
        _demandOffLineArray = [NSMutableArray array];
    }
    return _demandOffLineArray;
}
-(NSMutableArray *)serviceOnLineArray
{
    if (!_serviceOnLineArray) {
        _serviceOnLineArray = [NSMutableArray array];
    }
    return _serviceOnLineArray;
}
-(NSMutableArray *)serviceOffLineArray
{
    if (!_serviceOffLineArray) {
        _serviceOffLineArray = [NSMutableArray array];
    }
    return _serviceOffLineArray;
}
-(NSMutableArray *)dataOnLineMuta
{
    if (!_dataOnLineMuta) {
        _dataOnLineMuta = [NSMutableArray array];
    }
    return _dataOnLineMuta;
}
-(NSMutableArray *)dataOffLineMuta
{
    if (!_dataOffLineMuta) {
        _dataOffLineMuta = [NSMutableArray array];
    }
    return _dataOffLineMuta;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.manager = [AFHTTPSessionManager manager];
    self.pageNum = 1;
//    self.pageSize = arc4random() % 3+3;
    self.pageSize = 10;
    self.downMode = [[HomeModel alloc]init];
    self.upModel = [[HomeModel alloc]init];
    self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(associationdelete:) name:@"associationdelete" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(associationoff:) name:@"associationoff" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(associationup:) name:@"associationup" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(delectDemand:) name:@"delectDemand" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downShelves:) name:@"downShelves" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onShelves:) name:@"onShelves" object:nil];

    [self.tableView registerNib:[UINib nibWithNibName:@"WriteRequirementTitleCell" bundle:nil] forCellReuseIdentifier:identifierTitle];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyShopDemandCell" bundle:nil] forCellReuseIdentifier:identifierNeed];
    [self.tableView registerNib:[UINib nibWithNibName:@"MyShopServiceCell" bundle:nil] forCellReuseIdentifier:identifierService];
}
- (void)setSearchText:(NSString *)searchText
{
    _searchText = searchText;
    self.serviceOnLineArray = nil;
    self.serviceOffLineArray = nil;
    self.demandOnLineArray = nil;
    self.demandOffLineArray = nil;
    XLog(@"店铺内搜索:%@",searchText);
    [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
    [WSProgressHUD show];
    //使用GCD的信号量 dispatch_semaphore_t 创建同步请求
    dispatch_group_t group =dispatch_group_create();
    dispatch_queue_t globalQueue=dispatch_get_global_queue(0, 0);
    dispatch_semaphore_t semaphore= dispatch_semaphore_create(0);
    dispatch_group_async(group, globalQueue, ^{
        for (int i = 0; i<2; i++) {
            if (i == 0) {
                self.urlString = @"http://www.qichangkeji.vip/sj/association/shopSearch";
                self.dict = @{
                              @"uid":[UserDefaultsHelper readUid],
                              @"token":[UserDefaultsHelper readToken],
                              @"param":searchText,
                              @"page":[NumberSwitchString numberSwitchString:self.pageNum],
                              @"rows":[NumberSwitchString numberSwitchString:self.pageSize]
                              };
            }else {
                self.urlString = @"http://www.qichangkeji.vip/sj/demand/selectMyShopDemand";
                self.dict = @{
                              @"uid":[UserDefaultsHelper readUid],
                              @"token":[UserDefaultsHelper readToken],
                              @"content":searchText,
                              @"pageSize":[NumberSwitchString numberSwitchString:self.pageSize],
                              @"pageNumber":[NumberSwitchString numberSwitchString:self.pageNum]
                              };
            }
            [self.manager POST:self.urlString parameters:self.dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                XLog(@"HomeresponseObject:%@",responseObject);
                NSArray *date = [responseObject objectForKey:@"date"];
                if (i == 0) {
                    for (NSDictionary *dict in date) {
                        ServiceModel *model = [ServiceModel mj_objectWithKeyValues:dict];
                        if (model.status == 1 ) {
                            [self.serviceOnLineArray addObject:model];
                        }else {
                            [self.serviceOffLineArray addObject:model];
                        }
//                        [self.serviceArray addObject:model];
                    }
                }else {
                    for (NSDictionary *dict in date) {
                        HomeModel *model = [HomeModel mj_objectWithKeyValues:dict];
                        XLog(@"dictdemand:%@",dict);
                        if (model.status == 1 ) {
                            [self.demandOnLineArray addObject:model];
                        }else {
                            [self.demandOffLineArray addObject:model];
                        }
//                        [self.demandArray addObject:model];
                    }
                }
                XLog(@"self.dataOnLineMuta:%@",self.dataOnLineMuta);
                XLog(@"self.dataOffLineMuta:%@",self.dataOffLineMuta);
                dispatch_semaphore_signal(semaphore);
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                XLog(@"error:%@",error);
                dispatch_semaphore_signal(semaphore);
            }];
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
        }
        
    });
    
    dispatch_group_notify(group, dispatch_get_global_queue(0, 0), ^{
        NSLog(@"%@---全部结束。。。",[NSThread currentThread]);
        dispatch_async(dispatch_get_main_queue(), ^{
            XLog(@"serviceOnLineArray:%@",self.serviceOnLineArray);
            XLog(@"serviceOffLineArray:%@",self.serviceOffLineArray);
            XLog(@"dataOnLineMuta:%@",self.dataOnLineMuta);
            XLog(@"demandOnLineArray:%@",self.demandOnLineArray);
            if (!self.serviceOnLineArray.count&&!self.serviceOffLineArray.count&&!self.dataOnLineMuta.count&&!self.demandOnLineArray.count) {
                self.tableView.emptyDataSetSource = self;
                self.tableView.emptyDataSetDelegate = self;
            }
            [self.tableView reloadData];
            [WSProgressHUD dismiss];
        });
    });
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return self.serviceOnLineArray.count||self.demandOnLineArray.count?self.serviceOnLineArray.count+self.demandOnLineArray.count+1:0;
    }else {
        return self.serviceOffLineArray.count||self.demandOffLineArray.count?self.serviceOffLineArray.count+self.demandOffLineArray.count+1:0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView  setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    UITableViewCell *defaultCell = [[UITableViewCell alloc]init];
    if (indexPath.row == 0) {
        WriteRequirementTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierTitle forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        switch (indexPath.section) {
            case 0:
                cell.titleL.text = @"已上架需求";
                break;
            case 1:
                cell.titleL.text = @"未上架需求";
                break;
            default:
                break;
        }
        return cell;
    }else {
        if (indexPath.section == 0) {
            if (self.serviceOnLineArray.count) {
                if ( indexPath.row <= self.serviceOnLineArray.count) {
                    MyShopServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierService forIndexPath:indexPath];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.indexPath = indexPath;
                    cell.delegate = self;
                    [cell.onOffLineBtn setTitle:@"下架" forState:UIControlStateNormal];
                    [cell.onOffLineBtn setTitleColor:kLabel102Color forState:UIControlStateNormal];
                    ServiceModel *model = self.serviceOnLineArray[indexPath.row-1];
                    cell.serviceModel = model;
                    defaultCell = cell;
                    return cell;
                }else {
                    if (self.demandOnLineArray.count) {
                        MyShopDemandCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierNeed forIndexPath:indexPath];
                        cell.selectionStyle = UITableViewCellSelectionStyleNone;
                        cell.delegate = self;
                        cell.indexPath = indexPath;
                        [cell.onOffLineBtn setTitle:@"下架" forState:UIControlStateNormal];
                        [cell.onOffLineBtn setTitleColor:kLabel102Color forState:UIControlStateNormal];
                        HomeModel *model = self.demandOnLineArray[indexPath.row-1-self.serviceOnLineArray.count];
                        cell.homeModel = model;
                        defaultCell = cell;
                        return cell;
                    }
                }
            }else {
                if (self.demandOnLineArray.count) {
                    MyShopDemandCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierNeed forIndexPath:indexPath];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.delegate = self;
                    cell.indexPath = indexPath;
                    [cell.onOffLineBtn setTitle:@"下架" forState:UIControlStateNormal];
                    [cell.onOffLineBtn setTitleColor:kLabel102Color forState:UIControlStateNormal];
                    HomeModel *model = self.demandOnLineArray[indexPath.row-1-self.serviceOnLineArray.count];
                    cell.homeModel = model;
                    defaultCell = cell;
                    return cell;
                }
            }
            return defaultCell;
        }else {
            if (self.serviceOffLineArray.count) {
                if ( indexPath.row <= self.serviceOffLineArray.count) {
                    MyShopServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierService forIndexPath:indexPath];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.indexPath = indexPath;
                    cell.delegate = self;
                    [cell.onOffLineBtn setTitle:@"上架" forState:UIControlStateNormal];
                    [cell.onOffLineBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:152/255.0 blue:0 alpha:1] forState:UIControlStateNormal];
                    ServiceModel *model = self.serviceOffLineArray[indexPath.row-1];
                    cell.serviceModel = model;
                    defaultCell = cell;
                    return cell;
                }else {
                    if (self.demandOffLineArray.count) {
                        MyShopDemandCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierNeed forIndexPath:indexPath];
                        cell.selectionStyle = UITableViewCellSelectionStyleNone;
                        cell.delegate = self;
                        cell.indexPath = indexPath;
                        [cell.onOffLineBtn setTitle:@"上架" forState:UIControlStateNormal];
                        [cell.onOffLineBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:152/255.0 blue:0 alpha:1] forState:UIControlStateNormal];
                        HomeModel *model = self.demandOffLineArray[indexPath.row-1-self.serviceOffLineArray.count];
                        cell.homeModel = model;
                        defaultCell = cell;
                        return cell;
                    }
                }
                
            }else {
                if (self.demandOffLineArray.count) {
                    MyShopDemandCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierNeed forIndexPath:indexPath];
                    cell.selectionStyle = UITableViewCellSelectionStyleNone;
                    cell.delegate = self;
                    cell.indexPath = indexPath;
                    [cell.onOffLineBtn setTitle:@"上架" forState:UIControlStateNormal];
                    [cell.onOffLineBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:152/255.0 blue:0 alpha:1] forState:UIControlStateNormal];
                    HomeModel *model = self.demandOffLineArray[indexPath.row-1];
                    cell.homeModel = model;
                    defaultCell = cell;
                    return cell;
                }
            }
            return defaultCell;
        }
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 60;
    }else {
        CGFloat height = 0;
        if (indexPath.section == 0) {
            if (self.serviceOnLineArray.count) {
                if ( indexPath.row <= self.serviceOnLineArray.count) {
                    height = 130;
                }else {
                    height = 144;
                }
            }else {
                if (self.demandOnLineArray.count) {
                    height = 144;
                }
            }
        }else {
            if (self.serviceOffLineArray.count) {
                if ( indexPath.row <= self.serviceOffLineArray.count) {
                    height = 130;
                }else {
                    height = 144;
                }
            }else {
                height = 144;
            }
        }
        return height;
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row != 0) {
        if (self.serviceOnLineArray.count) {
            if ( indexPath.row <= self.serviceOnLineArray.count) {
                ServiceModel *model = self.serviceOnLineArray[indexPath.row-1];
                if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                    [self.delegate myShopSearchTabVC:self withServiceModel:model withHomeModel:nil];
                }
            }else {
                if (self.demandOnLineArray.count) {
                    HomeModel *model = self.demandOnLineArray[indexPath.row-1-self.serviceOnLineArray.count];
                    if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                        [self.delegate myShopSearchTabVC:self withServiceModel:nil withHomeModel:model];
                    }
                }
            }
        }else {
            if (self.demandOnLineArray.count) {
                HomeModel *model = self.demandOnLineArray[indexPath.row-1-self.serviceOnLineArray.count];
                if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                    [self.delegate myShopSearchTabVC:self withServiceModel:nil withHomeModel:model];
                }
            }
        }
    }else if (indexPath.row != 0) {
        if (self.serviceOffLineArray.count) {
            if ( indexPath.row <= self.serviceOffLineArray.count) {
                ServiceModel *model = self.serviceOffLineArray[indexPath.row-1];
                if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                    [self.delegate myShopSearchTabVC:self withServiceModel:model withHomeModel:nil];
                }
            }else {
                if (self.demandOffLineArray.count) {
                    HomeModel *model = self.demandOffLineArray[indexPath.row-1-self.serviceOffLineArray.count];
                    if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                        [self.delegate myShopSearchTabVC:self withServiceModel:nil withHomeModel:model];
                    }
                }
            }
            
        }else {
            if (self.demandOffLineArray.count) {
                HomeModel *model = self.demandOffLineArray[indexPath.row-1];
                if ([self.delegate respondsToSelector:@selector(myShopSearchTabVC:withServiceModel:withHomeModel:)]) {
                    [self.delegate myShopSearchTabVC:self withServiceModel:nil withHomeModel:model];
                }
            }
        }
    }
    
}
#pragma mark-代理:删除,下架,修改,操作
- (void)myShopServiceCell:(MyShopServiceCell *)myShopServiceCell withBtn:(UIButton *)btn withIndexPath:(NSIndexPath *)indexPath
{
    XLog(@"服务上下架");
    [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
    [WSProgressHUD show];
    self.indexPath = indexPath;
    XLog(@"btn.tag:%ld",(long)btn.tag);
    if (indexPath.section == 0) {
        ServiceModel *model = self.serviceOnLineArray[indexPath.row -1];
        NSString *ids = [NSString stringWithFormat:@"%ld",model.id];
        self.tag = btn.tag;
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      @"aid":ids,
                      };
        if (btn.tag == 0) {//delete
            
            [CustomeManager POSTWithURLIndex:57 parameters:self.dict success:^(NSDictionary *dict) {
                
            } failure:^(NSError *error) {
                
            }];
            
        }else if (btn.tag == 1) {//off
            [CustomeManager POSTWithURLIndex:58 parameters:self.dict success:^(NSDictionary *dict) {
                
            } failure:^(NSError *error) {
                
            }];
        }
        
    }else {
        ServiceModel *model = self.serviceOffLineArray[indexPath.row -1];
        NSString *ids = [NSString stringWithFormat:@"%ld",model.id];
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      @"aid":ids,
                      };
        if (btn.tag == 0) {
            [CustomeManager POSTWithURLIndex:57 parameters:self.dict success:^(NSDictionary *dict) {
                
            } failure:^(NSError *error) {
                
            }];
        }else if (btn.tag == 1) {
            [CustomeManager POSTWithURLIndex:59 parameters:self.dict success:^(NSDictionary *dict) {
                
            } failure:^(NSError *error) {
                
            }];
        }
    }
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
    
    
}
#pragma mark-代理:删除
-(void)associationdelete:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"dict:%@",dict);
    NSString *message = [info.userInfo objectForKey:@"message"];
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //        [WSProgressHUD dismiss];
        if (self.indexPath.section == 0) {
            if (self.tag == 0) {
//                ServiceModel *model = self.serviceOnLineArray[indexPath.row -1];
                [self.serviceOnLineArray removeObjectAtIndex:self.indexPath.row -1];
            }else {
                [self.serviceOffLineArray removeObjectAtIndex:self.indexPath.row -1];
            }
            [self.tableView reloadRowsAtIndexPaths:@[self.indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }
        
    });
}
#pragma mark-代理:下架
-(void)associationoff:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"servicedictOff:%@",dict);
    NSString *message = [info.userInfo objectForKey:@"message"];
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.serviceOffLineArray addObject:self.serviceOnLineArray[self.indexPath.row -1]];
        [self.serviceOnLineArray removeObjectAtIndex:self.indexPath.row -1];
//        [self.tableView beginUpdates];
//        [self.tableView deleteRowsAtIndexPaths:@[self.indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
//        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
//        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
        [self.tableView reloadData];
//        [self.tableView endUpdates];
    });
}
#pragma mark-代理:上架
-(void)associationup:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"上架dict:%@",dict);
    NSString *message = [info.userInfo objectForKey:@"message"];
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        [self reloadInternetData];
        XLog(@"self.indexPath.section:%ld---self.indexPath.row:%ld",self.indexPath.section,self.indexPath.row);
        [self.serviceOnLineArray addObject:self.serviceOffLineArray[self.indexPath.row -1]];
        [self.serviceOffLineArray removeObjectAtIndex:self.indexPath.row -1];
        [self.tableView reloadData];
    });
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
#pragma mark-代理:删除,下架,修改,操作,联系...
- (void)myShopDemandCell:(MyShopDemandCell *)myShopDemandCell withClickBtn:(UIButton *)clickBtn withIndexPath:(NSIndexPath *)indexPath
{
    if (clickBtn.tag != 4&&clickBtn.tag !=5) {
        [WSProgressHUD setProgressHUDIndicatorStyle:WSProgressHUDIndicatorBigGray];
        [WSProgressHUD show];
    }
    XLog(@"wwqdqwdwqdwqqwdqwqwqwq");
    XLog(@"clickBtn.tag:%ld",clickBtn.tag);
    self.indexPath = indexPath;
    if (indexPath.section == 0) {
        self.upModel = self.demandOnLineArray[indexPath.row -1-self.serviceOnLineArray.count];
        NSString *ids = [NSString stringWithFormat:@"%ld",self.upModel.id];
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      @"id":ids,
                      };
        XLog(@"self.dict:%@",self.dict);
        XLog(@"clickBtn.tag:%ld",clickBtn.tag);
        switch (clickBtn.tag) {
            case 0://删除
            {
                [CustomeManager POSTWithURLIndex:54 parameters:self.dict success:^(NSDictionary *dict) {
                    
                } failure:^(NSError *error) {
                    
                }];
            }
                break;
            case 1://下架
            {
                [CustomeManager POSTWithURLIndex:55 parameters:self.dict success:^(NSDictionary *dict) {
                    
                } failure:^(NSError *error) {
                    
                }];
            }
                break;
            case 2:
            {
            }
                break;
            case 3:
            {
            }
                break;
            default:
            {
                XLog(@"clickBtn.selected:%d",clickBtn.selected);
                self.upModel.show = clickBtn.selected;
            }
                break;
        }
        
    }else {
        self.downMode = self.demandOffLineArray[indexPath.row -1-self.serviceOffLineArray.count];
        NSString *ids = [NSString stringWithFormat:@"%ld",self.downMode.id];
        self.dict = @{
                      @"uid":[UserDefaultsHelper readUid],
                      @"token":[UserDefaultsHelper readToken],
                      @"id":ids,
                      };
        XLog(@"self.dict:%@",self.dict);
        XLog(@"clickBtn.tag:%ld",clickBtn.tag);
        switch (clickBtn.tag) {//删除
            case 0:
            {
                [CustomeManager POSTWithURLIndex:54 parameters:self.dict success:^(NSDictionary *dict) {
                    
                } failure:^(NSError *error) {
                    
                }];
            }
                break;
            case 1:
            {
                [CustomeManager POSTWithURLIndex:56 parameters:self.dict success:^(NSDictionary *dict) {
                    
                } failure:^(NSError *error) {
                    
                }];
            }
                break;
            case 2:
            {
            }
                break;
                
            default:
            {
                XLog(@"clickBtn.selected:%d",clickBtn.selected);
                self.downMode.show = clickBtn.selected;
            }
                break;
        }
    }
    [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
#pragma mark-代理:删除
-(void)delectDemand:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"dict:%@",dict);
    NSString *message = [info.userInfo objectForKey:@"message"];
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:message];
//    [self reloadInternetData];
}
#pragma mark-代理:下架
-(void)downShelves:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"下架dict:%@",dict);
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"下架成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //        [WSProgressHUD dismiss];
//        [self reloadInternetData];
        [self.demandOffLineArray addObject:self.demandOnLineArray[self.indexPath.row -1-self.serviceOnLineArray.count]];
        [self.demandOnLineArray removeObjectAtIndex:self.indexPath.row - 1 -self.serviceOnLineArray.count];
        [self.tableView reloadData];
    });
    XLog(@"self.indexPath.section:%ld---self.indexPath.row:%ld",self.indexPath.section,self.indexPath.row);
}
#pragma mark-代理:上架
-(void)onShelves:(NSNotification *)info
{
    NSDictionary *dict = info.userInfo;
    XLog(@"上架dict:%@",dict);
    [WSProgressHUD showImage:[UIImage imageNamed:@""] status:@"上架成功"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //        [WSProgressHUD dismiss];
//        [self reloadInternetData];
        [self.demandOnLineArray addObject:self.demandOffLineArray[self.indexPath.row -1-self.serviceOffLineArray.count]];
        [self.demandOffLineArray removeObjectAtIndex:self.indexPath.row -1-self.serviceOffLineArray.count];
        [self.tableView reloadData];
    });
    XLog(@"self.indexPath.section:%ld---self.indexPath.row:%ld",self.indexPath.section,self.indexPath.row);
}
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    UIImage *image = [UIImage imageNamed:@"empty"];
    return image;
}
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *title = [NSBundle bundleLocalizedStringForKey:@"noData"];
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont boldSystemFontOfSize:14],
                                 NSForegroundColorAttributeName:kLabel102Color
                                 };
    return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}
@end
